﻿/*
 * KLF Headless Browser
 * Written by Kris Oye <kristianoye@gmail.com>
 * Copyright (C) 2011-2012.  All rights reserved.
 */
namespace KLF.Lib.Browser.DOM.Events
{
    #region Using Statements

    using KLF.Lib.Browser.DOM.View;

    #endregion

    public interface IUIEvent : IEvent
    {
    }

    /// <summary>
    /// The UIEvent interface provides specific contextual information 
    /// associated with User Interface events.
    /// </summary>
    public class UIEvent : Event
    {
        #region Constructors

        internal UIEvent(string _type)
        {
            type = _type;

            switch (_type.ToLowerInvariant())
            {
                case "domfocusin":
                case "domfocusout":
                    bubbles = true;
                    cancelable = false;
                    break;

                case "domactive":
                    bubbles = true;
                    cancelable = true;
                    break;
            }
        }

        #endregion

        #region DOM Level 2 Events Compliance

        /// <summary>
        /// 
        /// </summary>
        public int detail { get; set; }

        /// <summary>
        /// The initUIEvent method is used to initialize the value of a UIEvent
        /// created through the DocumentEvent interface. This method may only 
        /// be called before the UIEvent has been dispatched via the 
        /// dispatchEvent method, though it may be called multiple times during
        /// that phase if necessary. If called multiple times, the final 
        /// invocation takes precedence.
        /// </summary>
        /// <param name="typeArg"></param>
        /// <param name="canBubbleArg"></param>
        /// <param name="cancelableArg"></param>
        /// <param name="viewArg"></param>
        /// <param name="detailArg"></param>
        public void initUIEvent(string typeArg, bool canBubbleArg, bool cancelableArg, IAbstractView viewArg, int detailArg)
        {
            if (!dispatched)
            {
                base.initEvent(typeArg, canBubbleArg, cancelable);
                detail = detailArg;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public IAbstractView view
        {
            get;
            internal set;
        }

        #endregion
    }
}
